import type { UserInfo } from '../store/types'
import type { RouteRecordRaw } from 'vue-router'
import Layout from '../layout/index.vue'

// 模拟延迟
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

// 模拟登录接口
export async function login(data: {
  username: string;
  password: string;
}): Promise<{ token: string }> {
  await delay(1000) // 模拟网络延迟

  if (data.username === 'admin' && data.password === '123') {
    return {
      token: 'mock-token-' + Date.now()
    }
  }
  throw new Error('用户名或密码错误')
}

// 模拟获取用户信息
export async function getUserInfo(): Promise<UserInfo> {
  await delay(500)
  return {
    username: 'admin',
    avatar: '',
    roles: ['admin']
  }
}

// 模拟获取路由配置
export async function getRoutes(): Promise<RouteRecordRaw[]> {
  await delay(500)
  return [
    {
      path: '/dashboard',
      component: Layout,
      children: [
        {
          path: 'index',
          name: 'Dashboard',
          component: () => import('../views/dashboard/index.vue'),
          meta: { title: '首页', icon: 'DashboardOutlined' }
        }
      ]
    },
    {
      path: '/system',
      component: Layout,
      meta: { title: '系统管理', icon: 'SettingOutlined' },
      children: [
        {
          path: 'user',
          name: 'User',
          component: () => import('../views/system/user/index.vue'),
          meta: { title: '用户管理', icon: 'UserOutlined' }
        },
        {
          path: 'role',
          name: 'Role',
          component: () => import('../views/system/role/index.vue'),
          meta: { title: '角色管理', icon: 'TeamOutlined' }
        }
      ]
    }
  ]
}

// 模拟登出接口
export async function logout(): Promise<void> {
  await delay(500)
  return
} 